//设置缓存
function set_cache(key, value) {
    if (key == '') return false;
    localStorage.setItem(key, value);
}
//读取缓存
function get_cache(key) {
    return localStorage.getItem(key);
}
//删除缓存
function remove_cache(key) {
    localStorage.removeItem(key);
}

//写⼊cookie
function setCookie2(name, value, time) {
    var Days = time | 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

//获取cookie
function getCookie2(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}


function setCookie(cname, cvalue, exdays) {
    var exp = new Date();
    exp.setTime(exp.getTime() + exdays * 24 * 60 * 60 * 1000); //6天过期
    document.cookie =
        cname + "=" + unescape(cvalue) + ";expires=" + exp.toGMTString();
    return true;
}

//读取cookie
function getCookie(name) {
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    // var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr) return unescape(arr[2]);
    return null;
}


//删除cookie
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

//格式化时间戳
//getLocalTime(1470800400);
//输出：2016-08-10 11:40:00
function getLocalTime(time) {
    var datetime = new Date();
    datetime.setTime(parseInt(time + '000'));
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
    var hour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
    var minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
    var second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
    return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second

}

//获取get参数
function get(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}